package com.bkgy.modular.subjectQuery.service.impl;

import com.bkgy.modular.datacollect_bx.bean.JDataSave642;
import com.bkgy.modular.subjectQuery.entity.KeyValueEntity;
import com.bkgy.modular.subjectQuery.entity.ShareData;
import com.bkgy.modular.subjectQuery.service.RightDataTabService;
import com.bkgy.sys.common.entity.ResultData;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author ZhuHongKai
 * @version 1.0
 * @ClassName CalCurve2130Impl
 * @date 2023/1/12 17:41
 */
@Service("cal_curve")
public class CalCurve2130Impl implements RightDataTabService {
    @Resource
    private MongoTemplate mongoTemplate;

    @Override
    public ResultData findByRightData(Integer pageIndex, Integer pageSize, String coilId, String hotId, ShareData shareData) {
        // JDataSave642
        Query query = new Query(Criteria.where("extid").is(hotId));
        List<JDataSave642> jDataSave642List = mongoTemplate.find(query, JDataSave642.class);
        // 创建分页对象
        // PageHelper.startPage(pageIndex,pageSize);
        List<KeyValueEntity> mapList = new ArrayList<>();
        for (JDataSave642 item : jDataSave642List) {
            Map<String, List<Double>> map = item.getRow();
            // 根据map集合中的key进行循环,将key和value拆开
            for (String string : map.keySet()) {
                KeyValueEntity entity = new KeyValueEntity();
                List<Double> list = map.get(string);
                entity.setKey(string);
                for (Double aDouble : list) {
                    entity.setValue(aDouble);
                }
                mapList.add(entity);
            }
        }
        // List<KeyValueEntity> lists = mapList.stream().skip((pageIndex - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
        return ResultData.ResultDataSuccess(mapList,mapList.size());
    }
}
